<template>
  <div class="app-container">
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" height="500px">

    
          <div class="head-container">
            <el-input v-model="orgName" placeholder="请输入机构名称" clearable size="small" prefix-icon="el-icon-search"
              style="margin-bottom: 20px" />
          </div>
          <div class="head-container">
          <el-tree :data="orgOptions" :props="defaultProps" :expand-on-click-node="false"
            :filter-node-method="filterNode" ref="tree" node-key="id" highlight-current
            @node-click="handleNodeClick" />
        </div>
    
    </el-dialog>
  </div>
</template>

<script>
import Treeselect from "@riophae/vue-treeselect";
import { orgTreeSelect } from "@/api/system/user";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "OrgSelect",
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示查询条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      // 弹出层标题
      title: "",
      // 机构树选项
      orgOptions: undefined,
      // 是否显示弹出层
      open: false,
      // 机构名称
      orgName: undefined,
      // 默认密码
      initPassword: undefined,
      // 日期范围
      dateRange: [],
      defaultProps: {
        children: "children",
        label: "name"
      },
      // 岗位选项
      postOptions: [],
      //租户列表
      tenantList: [],
      // 角色选项
      roleOptions: [],
      companyOptions: [],
      // 表单参数
      form: {},


      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phone: undefined,
        status: undefined,
        orgId: undefined
      },


    };
  },
  watch: {
    // 根据名称筛选机构树
    orgName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    // this.getList();

  },
  methods: {
    /** 查询用户列表 */

    init() {
      this.open=true;
      this.getList();
    },
    getList() {
      orgTreeSelect().then(response => {
        console.log(response.data);
        this.orgOptions = response.data;
      });
    },


    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      // this.queryParams.orgId = data.id;
      // this.handleQuery();
      this.$parent.orgId=data.id;
      this.$parent.orgName=data.label;
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },


  }
};
</script>